package com.cn.项目.飞机预约管理系统.Maininterface;

import com.cn.项目.utils.JdbcUtils;

import javax.swing.*;
import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

//显示公告面版
public class Showannouncement extends JPanel {

    public Showannouncement(){
        JPanel p1 = new JPanel();
        p1.setLayout(new BorderLayout());
        JPanel p2 = new JPanel();
        JLabel j1 = new JLabel("展示公告");
        p2.add(j1,JLabel.CENTER);
        j1.setFont(new Font("华文楷书", 1, 30));
        j1.setForeground(Color.red);
        p1.add(p2,"North");

        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null;
        Object atext = null;
        try {
           conn =  JdbcUtils.getConnection();
           String sql = "select *from announcement";
           st = conn.prepareStatement(sql);
           rs = st.executeQuery();
           JTextArea jta = new JTextArea(23, 20);

           while (rs.next()){
              atext = rs.getObject("atext");
              jta.append((String) atext);
        }
            JPanel p3 = new JPanel();
            System.out.println(atext);


            jta.setLineWrap(true);
            jta.setEditable(false);  // 设置为不可修改
            p3.add(jta);
            p1.add(p3,"Center");

            this.add(p1);
            this.setVisible(true);

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.release(conn, st, rs);
        }



    }
}
